// 
// Decompiled by Procyon v0.5.36
// 

package com.akamai.botman;

import com.cyberfend.cyfsecurity.*;
import java.net.*;
import android.util.*;
import org.json.*;
import android.os.*;
import java.io.*;

public final class b
{
    public static void a(final int f) throws java.lang.Exception {
        boolean b = false;
        Label_0036: {
            if (com.akamai.botman.d.o == 0L) {
                com.akamai.botman.d.o = android.os.SystemClock.uptimeMillis();
            }
            else if (android.os.SystemClock.uptimeMillis() - com.akamai.botman.d.o < 5000L) {
                b = false;
                break Label_0036;
            }
            b = true;
        }
        if (!b) {
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            return;
        }
        new java.lang.StringBuilder("before doing autopost type: ").append(f).append(" index:").append(com.akamai.botman.d.g);
        final java.lang.Throwable[] array2 = new java.lang.Throwable[0];
        com.akamai.botman.d.f = f;
        final java.lang.String a = com.cyberfend.cyfsecurity.CYFMonitor.b().a();
        final java.lang.String i = com.akamai.botman.d.i;
        final int length = a.length();
        if (com.akamai.botman.d.n + length > com.akamai.botman.d.k || com.akamai.botman.d.g >= 5) {
            final java.lang.Throwable[] array3 = new java.lang.Throwable[0];
            return;
        }
        com.akamai.botman.d.o = android.os.SystemClock.uptimeMillis();
        ++com.akamai.botman.d.g;
        new android.os.AsyncTask<java.lang.Void, java.lang.Void, java.lang.Void>() {
            java.net.HttpURLConnection a;
            java.io.DataOutputStream b;
            java.lang.String c = null;
            
            private java.lang.Void a() {
                try {
                    (this.a = (java.net.HttpURLConnection)new java.net.URL(com.akamai.botman.d.b + "api/v1/attempt").openConnection()).setReadTimeout(10000);
                    this.a.setConnectTimeout(15000);
                    this.a.setRequestMethod("POST");
                    this.a.setDoInput(true);
                    this.a.setDoOutput(true);
                    final java.lang.String encodeToString = android.util.Base64.encodeToString((com.akamai.botman.d.j + ":").getBytes(), 2);
                    this.a.setRequestProperty("Content-Type", "application/json");
                    this.a.setRequestProperty("Authorization", "Basic ".concat(java.lang.String.valueOf(encodeToString)));
                    final org.json.JSONObject jsonObject;
                    (jsonObject = new org.json.JSONObject()).put(com.akamai.botman.d.c, (java.lang.Object)a);
                    jsonObject.put("session_id", (java.lang.Object)i);
                    (this.b = new java.io.DataOutputStream(this.a.getOutputStream())).write(jsonObject.toString().getBytes("UTF-8"));
                    this.b.flush();
                    this.b.close();
                    if (this.a.getResponseCode() == 201) {
                        this.c = com.akamai.botman.b.a(this.a.getInputStream());
                        final org.json.JSONObject jsonObject2;
                        if ((this.c != "" || this.c != null) && (jsonObject2 = new org.json.JSONObject(this.c)).has("notification") && jsonObject2.get("notification").toString().equalsIgnoreCase("stop")) {
                            try {
                                new android.os.Handler(android.os.Looper.getMainLooper()).post((java.lang.Runnable)new java.lang.Runnable() {
                                    @java.lang.Override
                                    public final void run() {
                                        com.akamai.botman.b.a(i, true);
                                    }
                                });
                            }
                            catch (java.lang.Exception ex) {
                                new java.lang.StringBuilder("Exception occurred:").append(ex.getMessage());
                                final java.lang.Throwable[] array = new java.lang.Throwable[0];
                            }
                        }
                    }
                }
                catch (java.lang.Exception ex2) {
                    final java.lang.Throwable[] array2 = new java.lang.Throwable[0];
                }
                finally {
                    if (this.a != null) {
                        this.a.disconnect();
                    }
                }
                return null;
            }
        }.execute((java.lang.Object[])new java.lang.Void[0]);
        com.akamai.botman.d.n += length;
    }
    
    static void a(final java.lang.String s, final boolean b) {
        if (!b) {
            if (com.akamai.botman.t.c(com.akamai.botman.d.i)) {
                com.akamai.botman.d.d = false;
                return;
            }
            if (com.akamai.botman.t.c(s) || !s.equalsIgnoreCase(com.akamai.botman.d.i)) {
                com.akamai.botman.d.d = true;
            }
        }
        else if (!com.akamai.botman.t.c(s) && !com.akamai.botman.t.c(com.akamai.botman.d.i) && s.equalsIgnoreCase(com.akamai.botman.d.i)) {
            com.akamai.botman.d.d = false;
        }
    }
    
    public static void a(java.lang.String i) {
        final java.lang.String j = com.akamai.botman.d.i;
        com.akamai.botman.d.i = i;
        a(j, false);
        if ((com.akamai.botman.t.c(i = j) || !i.equalsIgnoreCase(com.akamai.botman.d.i)) && !com.akamai.botman.t.c(com.akamai.botman.d.i)) {
            try {
                final java.lang.Throwable[] array = new java.lang.Throwable[0];
                com.akamai.botman.e.a();
                com.akamai.botman.d.a();
                com.akamai.botman.s.a();
            }
            catch (java.lang.Exception ex) {
                new java.lang.StringBuilder("Exception occurred:").append(ex.getMessage());
                final java.lang.Throwable[] array2 = new java.lang.Throwable[0];
                com.akamai.botman.f.a(ex);
            }
        }
    }
    
    static java.lang.String a(final java.io.InputStream inputStream) {
        java.io.BufferedReader bufferedReader = null;
        final java.lang.StringBuilder sb = new java.lang.StringBuilder();
        try {
            bufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream));
            java.lang.String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
            try {
                bufferedReader.close();
            }
            catch (java.io.IOException ex) {
                ex.printStackTrace();
            }
        }
        catch (java.io.IOException ex2) {
            ex2.printStackTrace();
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                }
                catch (java.io.IOException ex3) {
                    ex3.printStackTrace();
                }
            }
        }
        finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                }
                catch (java.io.IOException ex4) {
                    ex4.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
}
